# -*- coding: utf-8 -*-
# created by Alberthch - 陈航  2021/7/15 20:49
# Description:你想构造一个字典，它是另外一个字典的子集
# example of extracting a subset from a dictionary
from pprint import pprint

prices = {
    'ACME': -45.23,
    'AAPL': 612.78,
    'IBM': -205.55,
    'HPQ': 37.20,
    'FB': -10.75
}
pprint(prices)
# Make a dictionary of all prices over 200
# 字典推导式
p1 = {key: value for key, value in prices.items() if value > 0}

print("All prices over 0")
pprint(p1)

# Make a dictionary of tech stocks
tech_names = {'AAPL', 'IBM', 'HPQ', 'MSFT'}
p2 = {key: value for key, value in prices.items() if key in tech_names}

print("All techs")
pprint(p2)
